// pages/scenter/editpass.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone:null,
    codeinfo:null,
    token:null,
    newpass:null,
    oldpass:null
  },
  getnewpass(e){
    let that = this
    that.setData({
      newpass:e.detail.value
    })
  },
  getokpass(e){
    let that = this
    that.setData({
      oldpass:e.detail.value
    })
  },
  okpass(e){
    let that = this
    if(that.data.newpass==that.data.oldpass){
    wx.request({
      url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
      data: {
       //请求后台的分页数据
       cmd:'setPayPwd',
       mobile:that.data.phone,
       token:that.data.token,
       yzm:that.data.codeinfo,
       IsCorp:0,
       Pwd:that.data.newpass,
      },
      method: "get",
      success(res) {
        if(res.data.STATUS=='Success'){
          wx.showToast({
            title: '设置密码成功',
            icon: 'success',
            duration: 2000
          })
          //重新授权登陆 获得缓存
          wx.login({
            success (res) {
              wx.getUserInfo({
                success: function(b) {
                  wx.setStorageSync('wxinfo',b.userInfo);
                  wx.request({
                    url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
                    data: {
                      code: res.code,
                      cmd: 'wxlogin',
                      officeid:1
                    },
                    header: {
                      'content-type': 'application/json' // 默认值
                    },
                    success (data) {
                      if(data.STATUS='Success'){
                        wx.setStorageSync('userInfo',data.data.DATA);
                        wx.setStorageSync('token',data.data.DATA.token);
                        wx.switchTab({
                        url: '../index/index',
                      })
                      }
                    }
                  });
                }
              })
             // console.log(res)
            }
          })
        }else{
          wx.showToast({
            title: '设置密码失败',
            icon: 'error',
            duration: 2000
          })
        }
      }
    })
  }else{
    wx.showToast({
      title: '请输入两次相同的密码',
      icon: 'error',
      duration: 2000
    })
  }
  },
  navigateBack() {
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    let token = wx.getStorageSync('token')
    that.setData({
      phone:options.phone,
      token:token,
      codeinfo:options.codeinfo,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let that = this
    that.setData({
      phone:e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})